<?php

class Admin_Forms_AddBannerForm extends Zend_Form{
	private $_messagesError = null;

	public function __construct($option=null){
        $this->setAction('')
				->setMethod('POST')
				->setAttrib('enctype', 'multipart/form-data')
				->setAttrib('class', 'form-horizontal')
                                ->setAttrib('style','float:left')
			    ->setAttrib('name', 'addProduct-form');
		
		$name = $this->createElement('text', 'name');
		$name->addValidator('NotEmpty');
		$name->getValidator('NotEmpty')->getMessages('Xin điền tên bài viết');
		$name->setRequired ( true )
		->addFilter('StringTrim')
		->setAttrib('class', 'input-xlarge')
		->setLabel('Tên bài viết');
		
		$link_url = $this->createElement('text', 'link_url');
		$link_url->addValidator('NotEmpty');
		$link_url->getValidator('NotEmpty')->getMessages('Xin điền tên bài viết');
		$link_url->setRequired ( true )
		->addFilter('StringTrim')
		->setAttrib('class', 'input-xlarge')
		->setLabel('Link');

		$description = new Zend_Form_Element_Textarea('description');
		$description->setLabel('Mô tả')
		->setAttrib('rows', 12)
		->setAttrib('cols', 40)
		->addFilter('StringTrim');
		
		$content = new Zend_Form_Element_Textarea('content');
		$content->setLabel('Nội dung')
		->setAttrib('rows', 12)
		->setAttrib('cols', 40)		
		->addFilter('StringTrim');
		$content->setAttrib('class','ckeditor');
		
		$avatar =$this->createElement("file", "avatar");
		$avatar
		 	  ->setLabel('Xin chọn ảnh nội dung')
		 	  ->setDestination(APPLICATION_PATH.'/../public/imagesnote/note/');
		$avatar->addValidator(new Zend_Validate_File_Extension(array('gif,png,jpg')));
		$avatar->addValidator(new Zend_Validate_File_FilesSize(array('min'=>1,'max'=>10000000,'bytestring'=>true)));
	    $avatar->setAttrib('class','fileupload fileupload-new');
		$cancel = $this->createElement('button', 'cancel',array('label'	=> 'Hủy bỏ','class'=>'btn btn-inverse','onclick'	=> 'windown:location = "' .'/admin/note'. '"'));
		$reset = $this->createElement('reset','reset',array('label'	=> 'Reset','class'=>'btn'));
		$submit = $this->createElement('submit','submit',array ('label' => 'Thêm'));
		$submit->setAttrib('class', 'btn btn-primary');	

		//SEO
		$seo_title = $this->createElement('text', 'seo_title');
		$seo_title->setLabel('SEO Title');

		$seo_keywords = $this->createElement ( 'textarea', 'seo_keywords');
		$seo_keywords->setOptions(array('cols' => '40', 'rows' => '4'));
        $seo_keywords->setLabel("SEO Keywords");
		
        $seo_description = $this->createElement ( 'textarea', 'seo_description');
        $seo_description->setOptions(array('cols' => '40', 'rows' => '4'));
        $seo_description->setLabel("SEO Description");

		//ADD
		//$this->addElement(new Element_CategorySelect('CatID'));
		$this->addElement($name);
		$this->addElement($link_url);
		// $this->addElement($description);
		$this->addElement($content)
		->addElement($avatar)
		// ->addElement($seo_title)
		// ->addElement($seo_keywords)
		// ->addElement($seo_description)
		
		->addElement($cancel)
		->addElement($reset)
		->addElement($submit);
		$this->setDecorators(array('FormElements',array('HtmlTag',array('tag'	=> 'div','width'=>'100%')),'form'));
		$this->setElementDecorators(array(
				'ViewHelper',
				'Errors',
				'Description',
				array(
						array('data'	=> 'HtmlTag'),
						array('tag'		=> 'div','class'	=> 'controls')),
				array('label',
						array('class'	=> 'control-label','requiredSuffix'=>'(*)')),
				array(
						array('row'	=> 'HtmlTag',),
						array('class'=>'control-group ')
				),
				array(
						array('ErrorsDiv' => 'HtmlTag'),
						array('tag' => 'span', 'placement' => Zend_Form_Decorator_Abstract::APPEND)
				)
		)
		);
		
		$this->getElement('avatar')->setDecorators(
				array(
						'File',
						'Errors',
						array(
						array('data'	=> 'HtmlTag'),
						array('tag'		=> 'div','class'	=> 'controls')),
				array('label',
						array('class'	=> 'control-label','requiredSuffix'=>'(*)')),
				array(
						array('row'	=> 'HtmlTag',),
						array('class'=>'control-group ')
				),
				array(
						array('ErrorsDiv' => 'HtmlTag'),
						array('tag' => 'span', 'placement' => Zend_Form_Decorator_Abstract::APPEND)
				)
				)
		);
		$submit->setDecorators(array(
				'ViewHelper',
		));
		$reset->setDecorators(array(
				'ViewHelper',
		));
		$cancel->setDecorators(array(
				'ViewHelper',
		)
		);
		$this->addDisplayGroup(array('submit','reset','cancel'),'action');
		$action = $this->getDisplayGroup('action');
		$action->setDecorators(array(
				'FormElements',
				'Fieldset',
				array('HtmlTag',array('tag'=>'div','class'	=> 'form-actions'))
		));
	}
	public function isError(){
		if (count($this->_messagesError)>0){
			return true;
		}
		else
			return false;
	}
	
	//tra ve mot mang cac loi
	public function getMessagesError(){
		return $this->_messagesError;
	}
        
}   
?>
